<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="指标月份">
        <el-date-picker
          v-model="queryParams.monthing"
          type="month"
          size="small"
          format="yyyy-MM"
          value-format="yyyy-MM"
          placeholder="选择月">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="战线单位" >
        <el-select
          v-model="queryParams.depId"
          placeholder="请选择"
          clearable
          size="small"
          @change="search"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.deptId"
            :label="dict.deptName"
            :value="dict.deptId"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
<!--        <span style="color: #646c9a;">-->
<!--           战线指标：0.00；剩余指标：0.00-->
<!--        </span>-->

      </el-form-item>
      <el-form-item>
        <el-button   type="success" icon="el-icon-s-order" size="mini" @click="saveBtn">保存指标</el-button>
        <el-button   type="primary" icon="el-icon-search" size="mini" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
      <el-table
        :data="tableData"
        border
        v-loading="loading"
        show-summary
        style="width: 100%">
        <el-table-column
          prop="depName"
          align="center"
          label="基层单位"
          width="180">
        </el-table-column>
        <el-table-column
          prop="beginMonthIndex"
          align="center"
          label="月初指标">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.beginMonthIndex"
              placeholder=""
              clearable
              size="mini"
            />
          </template>
        </el-table-column>
        <el-table-column
          prop="trimIndex"
          align="center"
          label="调整指标">
          <template slot-scope="scope">
            <el-input
              v-model="scope.row.trimIndex"
              placeholder=""
              clearable
              size="mini"
            />
          </template>
        </el-table-column>
        <el-table-column
          prop="amount3"
          align="center"
          label="合计指标">
          <template slot-scope="scope">
           <span> {{xiangjia(scope.row)}}</span>
          </template>
        </el-table-column>
      </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="search"
    />
  <procure-plan-des v-if="isprocureDes" @subSetChane="subSetChane" :pid="pid"></procure-plan-des>
  </div>
</template>

<script>
  import request from '@/utils/request'
  import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
  import procurePlanDes from '@/views/components/applicationXQ'



  export default {
    name: "Role",
    components:{
      procurePlanDes
    },
    data() {
      return {
        tableData: [],
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 日期范围
        dateRange: [],
        // 状态数据字典
        statusOptions: [],
        // 数据范围选项
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          monthing: '',
          depId: '',
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },

        isprocureDes:false,
        pid:null
      };
    },
    created() {
      this.getTime()
      this.getZhanxin()
    },
    methods: {
      getTime:function(){
        var myDate = new Date();
        var pp =myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
        if(pp<9){
          pp = "0"+pp
        }
        this.queryParams.monthing = myDate.getFullYear()+'-'+pp;
      },
      //获取站线数据
      getZhanxin:function(){
        request({
          url: '/system/dept/listFront',
          method: 'get',
        }).then(response => {
          this.statusOptions = response.data
          this.queryParams.depId =this.statusOptions[0].deptId
          this.search()
        });
      },
      saveBtn:function(){
        this.$confirm('确认要保存区队的消耗指标吗？', '提示信息？', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.bancun()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消保存'
          });
        });

      },
      //保存指标
      bancun:function(){
        request({
          url: '/system/index/add',
          method: 'post',
          data:this.tableData
        }).then(response => {
          if(response.code=='200'){
            this.$message({
              type: 'success',
              message: '保存成功!'
            });
          }
          this.search()
        });
      },
      xiangjia:function(row){
        debugger
        row.amount3 = row.beginMonthIndex/1+row.trimIndex/1
        return  row.amount3
      },
      //查询
      search:function(){
        this.loading=true
        request({
          url: '/system/index/list',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading = false
          this.tableData = response.rows
          this.total = response.total

        });
      },
      //表格编辑
      handleEdit:function (index,row) {
        console.log(row)
        var obj={
          name:'采购计划'
        }
        this.$router.push({path:'/purchaseGL/cgjhAdd',query:{data:obj}});
      },
      //删除
      handleDelete:function (index,row) {
        this.$confirm('确认删除?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      //采购计划
      cgjhadd:function () {
        console.log('tianjia')
        this.$router.push({path:'/purchaseGL/cgjhAdd',query:{userid:'55555'}});
      },
      //详情点击
      xingqing:function (row) {
        console.log(row)
        // this.$router.push({path:'/purchaseGL/applicationXQ',query:{userid:row.id}});
        this.pid=row.moduleId
        this.isprocureDes=true
      },
      subSetChane(info){
          this.isprocureDes=false
          this.pid=null
      },

    }
  };
</script>
